package com.JUC.cha03.sec05;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * future常用方法
 *
 * 3.对计算结果进行消费
 *  3.1. thenRun(Runnable runnable)    任务A执行完后执行B，并且B不需要A的结果
 *  3.2. thenAccept(Consumer action) 任务A执行完执行B，B需要A的结果，但是任务B无返回值
 *  3.3. theApple(Function fn)   任务A执行完执行B，B需要A的结果，同时任务B有返回值
 */
public class CompletableFutureAPI3Demo {

    public static void main(String[] args) {

        System.out.println(CompletableFuture.supplyAsync(() -> "result").thenRun(() ->{}).join());
        System.out.println(CompletableFuture.supplyAsync(() -> "resultA").thenAccept(c -> System.out.println(c)).join());
        System.out.println(CompletableFuture.supplyAsync(() -> "resultB").thenApply(f -> f + "resultC").join());

        /*CompletableFuture.supplyAsync(() ->{
            return 1;
        }).thenApply(f ->{
            return f + 2;
        }).thenApply(f ->{
            return f + 3;
        }).thenAccept(r ->{
            System.out.println(r);
        });*/



    }
}
